package cn.donting.jme.edit.scene;

import cn.donting.jme.edit.attribute.Attribute;
import com.jme3.export.*;
import lombok.Getter;
import lombok.Setter;

import java.io.IOException;
import java.util.ArrayList;

public class ControlAttributesMapper implements Savable {

    @Getter
    @Setter
    private String className;
    @Getter
    @Setter
    private String title;
    @Getter
    private ArrayList<Attribute> attributes = new ArrayList<>();

    public void addAttribute(Attribute attribute) {
        attributes.add(attribute);
    }


    @Override
    public void write(JmeExporter ex) throws IOException {
        OutputCapsule capsule = ex.getCapsule(this);
        capsule.writeSavableArrayList(attributes, "attributes", new ArrayList<Attribute>());
        capsule.write(className, "className", null);
        capsule.write(title, "title", null);
    }

    @Override
    public void read(JmeImporter im) throws IOException {
        InputCapsule capsule = im.getCapsule(this);
        attributes = capsule.readSavableArrayList("attributes", new ArrayList<Attribute>());
        className = capsule.readString("className", null);
        title = capsule.readString("title", null);
    }
}
